﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MKAdminCore.DTO.Web.Common;
using MKAdminCore.Filters;

namespace MKAdminCore.Controllers
{
    [MvcAuthorize]
    public class BaseMvcController : Controller
    {
        public UserInfo GetUserInfo()
        {
            var userInfo = new UserInfo();
            var claimsQuery = HttpContext.User.Claims;
            var claimsInfo = claimsQuery.Where(q => q.Type == "UserInfo").FirstOrDefault();
            if (!string.IsNullOrEmpty(claimsInfo.Value))
            {
                userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(claimsInfo.Value);
            } 

            return userInfo;
        }
    }
}